<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Notice extends Model
{
    const TYPE_PRODUCT = 1;
    const TYPE_CATEGORY = 2;
    const TYPE_COUPON = 3;

    protected static function boot()
    {
        parent::boot();

        static::saving(function ($model){
            $model->type_id = 0;
            $model->type = 0;
        });
    }

    public function cover()
    {
        return $this->hasOne(Image::class, 'type_id')
            ->where('type', Image::NOTICE);
    }
}
